

#include "atomic_op_namespace.h"

#include <sys/atomic.h>

uint16_t
atomic_swap_16(volatile uint16_t *addr, uint16_t new)
	asm("__sync_lock_test_and_set_2");

uint16_t
atomic_swap_16(volatile uint16_t *addr, uint16_t new)
{
	uint16_t old;

	do {
		old = *addr;
	} while (atomic_cas_16(addr, old, new) != old);

	return old;
}

crt_alias(__atomic_exchange_2,__sync_lock_test_and_set_2)
